/**********************************************************************\

 Copyright 2012 Diggory Blake

 This file is part of klip-engine

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

\**********************************************************************/
#pragma once

#include <set>
#include <vector>
#include <queue>

class kEngine;
class kComponent;
class kGraphics;
class kSystem;
class kResources;
class kAnimation;
class kLog;
class kState;

#include "kbase.h"
#include "kcommon.h"

class kEngine : public kBase {
private:
	std::vector<kComponent*> _components;
	std::vector<kState*> _states;
	std::queue<std::function<void ()>> _stateTransition;
	kSystem* _system;
	kGraphics* _graphics;
	kResources* _resources;
	kAnimation* _animation;
	kLog* _log;
	bool _hasQuit;
	unsigned _startTime;
	float _deltaTime;
	unsigned _totalTime;
	int _fps;
	int _fpsAcc;
	float _timeAcc;

	kEngine();
public:
	static kEngine* create(INIT_LIST(kComponent* component, 0));
	inline void quit() {
		_hasQuit = true;
	}
	bool update();

	inline kSystem* getSystem() {
		return _system;
	}
	inline kGraphics* getGraphics() {
		return _graphics;
	}
	inline kResources* getResources() {
		return _resources;
	}
	inline kAnimation* getAnimation() {
		return _animation;
	}
	inline kLog* getLog() {
		return _log;
	}
	inline float getDeltaTime() {
		return _deltaTime;
	}
	inline unsigned getTotalTime() {
		return _totalTime;
	}
	inline int getFps() {
		return _fps;
	}
	void pushState(std::function<kState* ()> state);
	void popState();
};
